package com.lbd99.data.lbd.service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.cxf.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lbd99.data.lbd.dao.BIfibCupMapper;
import com.lbd99.data.lbd.dao.SysAccountMapper;
import com.lbd99.data.lbd.vo.BIfibCup;
import com.lbd99.data.lbd.vo.SysAccount;
import com.lbd99.data.utils.StrUtil;

@Service
@Transactional
public class BIfibCupService {
	
	@Autowired
	private BIfibCupMapper bIfibCupMapper;
	
	public Map<String, Object> getIfibList(){
		Map<String,Object> result = new HashMap<String,Object>();
		List<BIfibCup> list = bIfibCupMapper.getIfibList();
		result.put("rows", list);
		return result;
	}


	public Map<String,Object> rechargeIFBI(String amount,String tradePwd,Integer id,HttpSession httpSession){
		Map<String,Object> result = new HashMap<String,Object>(); 
		if(StringUtils.isEmpty(tradePwd) || StringUtils.isEmpty(amount)){
			result.put("isSuc", false);
			result.put("msg", "参数异常");
			return result;
		}
		SysAccount SysAccount = (SysAccount) httpSession.getAttribute("SESSION_INFO_OBJECT");
		if(SysAccount == null){
			result.put("isSuc", false);
			result.put("msg", "用户不存在");
			return result;
		}
		if(!StrUtil.doEncrypt(tradePwd).equals(SysAccount.getTradePwd())){
			result.put("isSuc", false);
			result.put("msg", "交易密码错误");
			return result;
		}
		
		BIfibCup bIfibCup = new BIfibCup();
		bIfibCup.setId(id);
		bIfibCup.setIfibNum(new BigDecimal(amount));
		bIfibCup.setUpdateBy(SysAccount.getTel());
		
		bIfibCupMapper.rechargeIFBI(bIfibCup);
		
		result.put("isSuc", true);
		result.put("msg", "充值成功");
		return result;
		
	}
	
}
